/**
 * ISSG Sony China 2010 
 *
 */
package cn.com.dragonsoftbravo.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @copyright Promoters Sell-thru System, ISSG, Sony China
 * @author William
 * @Revision
 * @date 2010-4-12
 */
public final class FileLinesReader {

	private String path = "";

	private final List<String> buffers = new ArrayList<String>();

	private FileLinesReader() {

	}

	/**
	 * @param path
	 *            the path to set
	 */
	public void setPath(String path) {
		this.path = path;
	}

	public static FileLinesReader instance(String path) {

		FileLinesReader flr = new FileLinesReader();
		flr.setPath(path);

		try {
			flr.process();

		} catch (Exception e) {

			throw new RuntimeException(e);
		}

		return flr;
	}

	private void process() throws Exception {
		/**
		 * change to charset UTF-8
		 */
		BufferedReader reader = new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(path)));

		try {
			String singleLine = reader.readLine();

			while (null != singleLine) {

				buffers.add(singleLine);

				singleLine = reader.readLine();
			}
		} finally {
			reader.close();
		}

	}

	/**
	 * 
	 * @return
	 */
	public List<String> getLines() {

		return buffers;
	}
}
